<template>
	<view class="page">
		<view class="info_box" style="padding-bottom: 40rpx;">
			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">室外接入信号测试</view>
				<view class="info_box_base_title" style="font-weight: bold;margin-top: 20rpx;">5G测试数据</view>
				<view class="info_box_base_item">
					<text>5G频段<text style="color: red;">*</text>：</text>
					<u--input v-model="params.frequency_5Gband" placeholder="请输入5G频段" border="bottom"></u--input>
				</view>

				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>NR-CI<text style="color: red;">*</text>：</text>
						<u--input v-model="params.nr_cl" placeholder="请输入NR-CI" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>NR-ARFCN<text style="color: red;">*</text>：</text>
						<u--input v-model="params.nr_arfcn" placeholder="请输入NR-ARFCN" border="bottom"></u--input>
					</view>
				</view>

				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>SS-RSRP<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入SS-RSRP" v-model="params.ss_rsrp" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>SS-RINR<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入SS-RINR" v-model="params.ss_rlnr" border="bottom"></u--input>
					</view>
				</view>

				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>下载速率<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入下载速率" v-model="params.download_5grate" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>上传速率<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入上传速率" v-model="params.upload_5gspeed" border="bottom"></u--input>
					</view>
				</view>

				<view class="info_box_base_title" style="font-weight: bold;margin-top: 20rpx;">4G测试数据</view>
				<view class="info_box_base_item">
					<text>4G频段<text style="color: red;">*</text>：</text>
					<u--input placeholder="请输入4G频段" v-model="params.frequency_4Gband" border="bottom"></u--input>
				</view>
				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>ECI<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入ECI" v-model="params.ecl" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>EARFCN<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入EARFCN" v-model="params.earfcn" border="bottom"></u--input>
					</view>
				</view>
				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>RSRP<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入RSRP" v-model="params.rsrp" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>SINR<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入SINR" v-model="params.slnr" border="bottom"></u--input>
					</view>
				</view>
				<view class="info_box_base_item">
					<view class="info_box_base_item" style="width: 50%;">
						<text>下载速率<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入下载速率" v-model="params.download_4grate" border="bottom"></u--input>
					</view>
					<view class="info_box_base_item" style="width: 50%;">
						<text>上传速率<text style="color: red;">*</text>：</text>
						<u--input placeholder="请输入上传速率" v-model="params.upload_4gspeed" border="bottom"></u--input>
					</view>
				</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">5G测试照片<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList1" width="65" height="65" @afterRead="afterRead"
							@delete="deletePic" name="1" multiple :maxCount="10"></u-upload>
					</view>
				</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">4G测试照片<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList2" width="65" height="65" @afterRead="afterRead"
							@delete="deletePic" name="2" multiple :maxCount="10"></u-upload>
					</view>
				</view>

			</view>

			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">覆盖前室内信号测试</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">5G测试照片<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList3" width="65" height="65" @afterRead="afterRead"
							@delete="deletePic" name="3" multiple :maxCount="10"></u-upload>
					</view>
				</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">4G测试照片<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList4" width="65" height="65" @afterRead="afterRead"
							@delete="deletePic" name="4" multiple :maxCount="10"></u-upload>
					</view>
				</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">覆盖前网络信号测试表<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList5" width="65" accept="file" height="65" @afterRead="afterRead"
							@delete="deletePic" name="5" :maxCount="1"></u-upload>
					</view>
				</view>

				<view class="info_box_base_item_1">
					<view class="info_box_base_item_img_title">设计方案<text style="color: red;">*</text></view>
					<view class="info_box_base_item_img_box">
						<u-upload :fileList="fileList6" width="65" accept="file" height="65" @afterRead="afterRead"
							@delete="deletePic" name="6" :maxCount="1"></u-upload>
					</view>
				</view>


				<view class="gcxt_b_wy_reason">
					<text sty>设计说明(选填)：</text>
					<u--input placeholder="请输入具体说明" v-model="design_desc" border="bottom"></u--input>
				</view>
			</view>


			<view class="btn" @click="next">下一步</view>
		</view>
	</view>
</template>

<script>
	import {
		api,
		apiBaseUrl,
		http
	} from '@/config/common.js'
	import {
		forEach
	} from '../../js_sdk/luch-request/luch-request/utils';
	export default {
		data() {
			return {
				id: '',
				fileList1: [],
				fileList2: [],
				fileList3: [],
				fileList4: [],
				fileList5: [],
				fileList6: [],
				params: {
					frequency_5Gband: '',
					nr_cl: '',
					nr_arfcn: '',
					ss_rsrp: '',
					ss_rlnr: '',
					download_5grate: '',
					upload_5gspeed: '',
					frequency_4Gband: '',
					ecl: '',
					earfcn: '',
					rsrp: '',
					slnr: '',
					download_4grate: '',
					upload_4gspeed: '',
					test_5gphotos: '',
					test_4gphotos: '',
					coverage_signal5gimg: '',
					coverage_signal4gimg: '',
					network_signal: '',
					design_scheme_img: '',

				},
				design_desc: '',
			}
		},
		components: {},
		filters: {},
		mounted() {},
		onLoad(e) {
			this.id = e.id
			this.lookInfo()
		},
		onShow() {},
		onPageScroll(e) {},
		beforeDestroy() {},
		methods: {
			/*
			 *删除多余key值
			 *targetList 目标数组
			 *keys 删除的key
			 */
			deleteArrayKey(targetList, keys) {
				if (targetList.length == 0) {
					return targetList
				}
				let newDate = []
				if (Array.isArray(keys)) {
					let mixed = Object.keys(...targetList).filter(x => !new Set(keys).has(x))
					newDate = JSON.parse(JSON.stringify(targetList, mixed))
				} else {
					newDate = JSON.parse(JSON.stringify(targetList, (k, v) => {
						if (k !== keys) {
							return v
						}
					}))
				}
				return newDate
			},
			//查找录入信息
			lookInfo() {
				uni.showLoading({})
				api.post('/api/shop/sunmit_surveyanddesign', {
					survey_id: this.id,
					type: 2
				}).then(res => {
					if (!res.data) {
						return
					}
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.design_desc = rst.data.design_desc
						rst.data = this.deleteArrayKey(rst.data, 'design_desc')
					 
						this.params = rst.data
						let temp_1 = []
						rst.data.test_5gphotos.forEach((item, index) => {
							temp_1.push({
								url: item
							})
						})
						this.fileList1 = temp_1

						let temp_2 = []
						rst.data.test_4gphotos.forEach((item, index) => {
							temp_2.push({
								url: item
							})
						})
						this.fileList2 = temp_2


						let temp_3 = []
						rst.data.coverage_signal5gimg.forEach((item, index) => {
							temp_3.push({
								url: item
							})
						})
						this.fileList3 = temp_3

						let temp_4 = []
						rst.data.coverage_signal4gimg.forEach((item, index) => {
							temp_4.push({
								url: item
							})
						})
						this.fileList4 = temp_4

					 
						this.fileList5 = [{url:rst.data.network_signal}]

						let temp_6 = []
						rst.data.design_scheme_img.forEach((item, index) => {
							temp_6.push({
								url: item
							})
						})
						this.fileList6 = temp_6
						
					}

				}).catch(err => {
					uni.hideLoading()
				})
			},
			next() {
				let rst = this.params
				rst.test_5gphotos = this.fileList1 ? this.fileList1.map(item => item.url).join(',') : [];
				rst.test_4gphotos = this.fileList2 ? this.fileList2.map(item => item.url).join(',') : [];
				rst.coverage_signal5gimg = this.fileList3 ? this.fileList3.map(item => item.url).join(',') : [];
				rst.coverage_signal4gimg = this.fileList4 ? this.fileList4.map(item => item.url).join(',') : [];
				rst.network_signal = this.fileList5 ? this.fileList5.map(item => item.url).join(',') : [];
				rst.design_scheme_img = this.fileList6 ? this.fileList6.map(item => item.url).join(',') : [];

				let temp_val = Object.values(rst);

				const hasEmptyValue = temp_val.some(item => !item);

				if (hasEmptyValue) {
					uni.$u.toast("请填写完整内容")
					return;
				}

				rst.survey_id = this.id
				rst.type = 1
				rst.design_desc = this.design_desc
				uni.showLoading({})
				api.post('/api/shop/sunmit_surveyanddesign', rst).then(res => {
					let rstt = res.data
					uni.hideLoading()
					
					if (rstt.code == 1) {
						uni.navigateTo({
							url: '/pages/kcsj/gcxx?id=' + this.id
						})
					} else {
						uni.$u.toast(rstt.msg)
					}

				}).catch(err => {
					uni.hideLoading()
				})

			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url, event)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url, event) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: apiBaseUrl + '/api/shop/upload',
						filePath: url,
						header: {
							'method': "xj_user",
							'token': uni.getStorageSync('token')
						},
						name: 'file',
						formData: {

						},
						success: (res) => {
							setTimeout(() => {
								let rst = JSON.parse(res.data)
								if (rst.code == 1) {
									resolve(rst.data)
								} else {
									uni.$u.toast(rst.msg)
									this.deletePic(event)
								}

							}, 500)
						}
					});
				})
			},
		}
	};
</script>

<style scoped>
	.btn {
		width: 500rpx;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		margin: 0 auto;
		margin-top: 40rpx;
		background-color: rgb(70, 179, 255);
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}

	::v-deep .uni-input-input {
		font-size: 26rpx;
	}

	::v-deep .uni-input-placeholder {
		font-size: 26rpx;
	}

	.info_box_base_item_img_title {
		font-size: 25rpx;
		margin: 20rpx 0;
	}

	.gcxt_b_wy_reason {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.gcxt_b_wy {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 20rpx 0;
	}

	.info_box_base {
		border: 1px solid rgb(235, 229, 229);
		padding: 20rpx;
		font-size: 25rpx;
		margin-top: 20rpx;
	}

	.info_box_base_item {
		line-height: 45rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.info_box {
		width: 710rpx;
		margin: 0 auto;

	}

	page {
		background-color: #fff;
	}
</style>